<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="en">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">






















<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">

<link rel="stylesheet" href="/css/main.css?v=7.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.2.0">


  <link rel="mask-icon" href="/images/logo.svg?v=7.2.0" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.2.0',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="Linux之vim使用详解">
<meta name="keywords" content="vim使用详解">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux之vim使用详解">
<meta property="og:url" content="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/index.html">
<meta property="og:site_name" content="MingRong&#39;s Boat">
<meta property="og:description" content="Linux之vim使用详解">
<meta property="og:locale" content="en">
<meta property="og:image" content="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223100320707.png">
<meta property="og:image" content="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105458430.png">
<meta property="og:image" content="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105516589.png">
<meta property="og:image" content="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105529558.png">
<meta property="og:image" content="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105607302.png">
<meta property="og:image" content="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105625388.png">
<meta property="og:updated_time" content="2021-02-23T03:03:52.908Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux之vim使用详解">
<meta name="twitter:description" content="Linux之vim使用详解">
<meta name="twitter:image" content="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223100320707.png">





  
  
  <link rel="canonical" href="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>Linux之vim使用详解 | MingRong's Boat</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">MingRong's Boat</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">O Captain! My Captain!</p>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="Toggle navigation bar">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>Home</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>Categories</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>Tags</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>Archives</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
      
    

    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>About</a>

  </li>

      
      
    </ul>
  

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/02/22/Linux相关/Linux之vim使用详解/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="MingRongChen">
      <meta itemprop="description" content="O Captain! My Captain!">
      <meta itemprop="image" content="/images/geass.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="MingRong's Boat">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux之vim使用详解

              
            
          </h1>
        

        <div class="post-meta">

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              

              
                
              

              <time title="Created: 2021-02-22 17:34:53" itemprop="dateCreated datePublished" datetime="2021-02-22T17:34:53+08:00">2021-02-22</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Edited on</span>
                
                <time title="Modified: 2021-02-23 11:03:52" itemprop="dateModified" datetime="2021-02-23T11:03:52+08:00">2021-02-23</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/Linux相关/" itemprop="url" rel="index"><span itemprop="name">Linux相关</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
                 Views:  
                <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
              </span>
            </span>
          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Linux之vim使用详解"><a href="#Linux之vim使用详解" class="headerlink" title="Linux之vim使用详解"></a>Linux之vim使用详解</h1><a id="more"></a>

<h2 id="vim简介"><a href="#vim简介" class="headerlink" title="vim简介"></a>vim简介</h2><p>Vim是从 vi 发展出来的一个文本编辑器。代码补全、编译及错误跳转等方便编程的功能特别丰富，在程序员中被广泛使用，和Emacs并列成为类Unix系统用户最喜欢的文本编辑器。</p>
<p>vim的设计理念是命令的组合。用户学习了各种各样的文本间移动/跳转的命令和其他的普通模式的编辑命令，并且能够灵活组合使用的话，能够比那些没有模式的编辑器更加高效的进行文本编辑。同时VIM与很多快捷键设置和正则表达式类似,可以辅助记忆。并且vim针对程序员做了优化。</p>
<h3 id="vim模式"><a href="#vim模式" class="headerlink" title="vim模式"></a>vim模式</h3><p>打开文件方法：vim filename，默认为编辑模式。</p>
<p>vim是模块化的编辑器，包含三种基本模式：</p>
<p>1、一般指令模式：Normal，默认模式，移动光标，剪切/粘贴文本。</p>
<p>2、编辑模式：Insert，插入模式，用于修改文本。</p>
<p>3、命令行命令模式：内置命令接口（extended command），用于保存、退出等。</p>
<h3 id="vim模式替换"><a href="#vim模式替换" class="headerlink" title="vim模式替换"></a>vim模式替换</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">一般指令模式 --&gt; 编辑模式：</span><br><span class="line">	i：insert, 在光标所在处输入</span><br><span class="line">	a: append，在光标在处后方输入</span><br><span class="line">	o：在光标所在处的下方打开一个新行</span><br><span class="line">	I：在光标所在行的行首输入</span><br><span class="line">	A：在光标所在行的行尾输入</span><br><span class="line">	O：在光标所在处的上方打开一个新行</span><br><span class="line">					</span><br><span class="line">编辑模式 --&gt; 一般指令模式</span><br><span class="line">	ESC</span><br><span class="line">					</span><br><span class="line">一般指令模式 --&gt; 命令行命令模式</span><br><span class="line">	:</span><br><span class="line">					</span><br><span class="line">命令行命令模式 --&gt; 一般指令模式模式</span><br><span class="line">	ESC，Enter</span><br></pre></td></tr></table></figure>

<h2 id="常用vim指令"><a href="#常用vim指令" class="headerlink" title="常用vim指令"></a>常用vim指令</h2><h3 id="一般指令模式"><a href="#一般指令模式" class="headerlink" title="一般指令模式"></a>一般指令模式</h3><h4 id="文件操作"><a href="#文件操作" class="headerlink" title="文件操作"></a>文件操作</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ZZ                     # 保存并退出</span><br><span class="line">ZQ                     # 不保存退出</span><br></pre></td></tr></table></figure>

<h4 id="光标"><a href="#光标" class="headerlink" title="光标"></a>光标</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> 字符间跳转</span><br><span class="line">h                          # 左</span><br><span class="line">j                          # 下</span><br><span class="line">k                          # 上</span><br><span class="line">l                          # 右			</span><br><span class="line"><span class="meta">#</span>COMMAND                   # 跳转由#指定的个数的字符</span><br><span class="line">5k                         # 向上跳转5个字符</span><br><span class="line">3l                         # 向右跳转3个字符</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 单词间跳转</span><br><span class="line">w                          # 下一个单词的词首</span><br><span class="line">e                          # 当前或后一个单词的词尾</span><br><span class="line">b                          # 当前或前一个单词的词首				</span><br><span class="line"><span class="meta">#</span>COMMAND                   # 跳转由#指定的个数的单词</span><br><span class="line">3w                         # 跳转到下三个单词的词首</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 行首行尾跳转</span><br><span class="line">^                          # 跳转至行首的第一个非空白字符</span><br><span class="line">0                          # 跳转至行首，数字 0 ，字母 O 和 o 是由编辑模式进入到输入模式</span><br><span class="line"><span class="meta">$</span>                          # 跳转至行尾		</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 当前页跳转</span><br><span class="line">H                          # 页首</span><br><span class="line">M                          # 页中间行</span><br><span class="line">L                          # 页底</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 行间跳转</span><br><span class="line"><span class="meta">#</span>G                         # 跳转至由#指定的行</span><br><span class="line">1G, gg                     # 第一行</span><br><span class="line">G                          # 最后一行</span><br><span class="line">5G                         # 跳转至第5行</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 句间跳转</span><br><span class="line">)                          # 下一句</span><br><span class="line">(                          # 上一句</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 段间跳转</span><br><span class="line">&#125;                          # 下一段</span><br><span class="line">&#123;                          # 上一段</span><br></pre></td></tr></table></figure>

<h4 id="翻屏"><a href="#翻屏" class="headerlink" title="翻屏"></a>翻屏</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Ctrl+f                     # 向文件尾翻一屏</span><br><span class="line">Ctrl+b                     # 向文件首部翻一屏</span><br><span class="line">Ctrl+d                     # 向文件尾部翻半屏</span><br><span class="line">Ctrl+u                     # 向文件首部翻半屏</span><br><span class="line">Enter                      # 按行向后翻</span><br></pre></td></tr></table></figure>

<h4 id="编辑命令"><a href="#编辑命令" class="headerlink" title="编辑命令"></a>编辑命令</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> 字符编辑</span><br><span class="line">x                          # 删除光标所在处的字符</span><br><span class="line"><span class="meta">#</span>x                         # 删除光标所在处起始的#个字符</span><br><span class="line">				</span><br><span class="line">xp                         # 交换光标所在处的字符与其后面的字符的位置</span><br><span class="line">~                          # 转换大小写</span><br><span class="line">J                          # 删除当前行后的换行符</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 替换命令</span><br><span class="line">r                          # 替换光标所在处的字符</span><br><span class="line">R                          # 切换成 REPLACE 模式，可以输入任意字符进行更换</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 删除命令 delete</span><br><span class="line">d                          # 删除命令，可结合光标跳转字符，实现范围删除</span><br><span class="line"><span class="meta">	d$</span>                     # 删除到行尾</span><br><span class="line">	d^                     # 删除到非空行首 </span><br><span class="line">	d0                     # 删除到行首				</span><br><span class="line">	dw                     # 删除光标所在处的单词或符号</span><br><span class="line">	d3w                    # 删除光标所在处的三个单词</span><br><span class="line">	de                     # 删除当前或下一个单词</span><br><span class="line">	db                     # 删除当前或前一个单词</span><br><span class="line"><span class="meta">	#</span>COMMAND               # 支持使用数字</span><br><span class="line">						</span><br><span class="line">	dd                     # 删除光标所在处的行</span><br><span class="line"><span class="meta">	#</span>dd                    # 删除光标所处的行起始的共#行</span><br><span class="line">	3dd                    # 删除光标所处的行起始的3行</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 复制命令</span><br><span class="line">y                          # 复制，工作行为相似于d命令</span><br><span class="line"><span class="meta">	y$</span>                     # 复制当前光标处到行尾</span><br><span class="line">	y^                     # 复制当前光标处到非空行首</span><br><span class="line">	y0                     # 复制当前光标处到行首</span><br><span class="line">					</span><br><span class="line">	ye                     # 复制当前或下一个单词</span><br><span class="line">	yw                     # 复制光标所在处的单词</span><br><span class="line">	yb                     # 复制当前或前一个单词</span><br><span class="line"><span class="meta">	#</span>COMMAND</span><br><span class="line">							</span><br><span class="line">	yy                     # 复制一整行</span><br><span class="line"><span class="meta">	#</span>yy                    # 复制#行</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 粘贴命令</span><br><span class="line">p           # 缓冲区中的内容如果为整行，则粘贴在当前光标所在行的下方</span><br><span class="line">	        # 否则，则粘贴至当前光标所在处的后方</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 改变命令 （相当于移动光标，删除，并进入输入模式）</span><br><span class="line"><span class="meta">c$</span>                         # 删除光标所在处至行尾，并切换到输入模式 </span><br><span class="line">c^                         # 非空行首</span><br><span class="line">c0                         # 行首</span><br><span class="line">					</span><br><span class="line">cb                         # 当前或前一个单词</span><br><span class="line">ce                         # 当前或下一个单词</span><br><span class="line">cw                         # 当前单词</span><br><span class="line"><span class="meta">#</span>COMMAND</span><br><span class="line">						</span><br><span class="line">cc                         # 删除光标所在的行，并转换为输入模式</span><br><span class="line"><span class="meta">#</span>cc                        # 删除光标所在行为起始行3行，并转换为输入模式</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 撤销模式</span><br><span class="line">撤销(undo)操作：</span><br><span class="line">	u                      # 撤销此前的操作；</span><br><span class="line"><span class="meta">	#</span>u                     # 撤销此前的#个操作；</span><br><span class="line">						</span><br><span class="line">Ctrl+r        	           # 撤销此前的撤销</span><br><span class="line">					</span><br><span class="line">	.                      # 重复执行前一个编辑操作</span><br></pre></td></tr></table></figure>

<h3 id="命令行命令模式"><a href="#命令行命令模式" class="headerlink" title="命令行命令模式"></a>命令行命令模式</h3><h4 id="文件操作-1"><a href="#文件操作-1" class="headerlink" title="文件操作"></a>文件操作</h4><p>在编辑模式下，输入“:”进入末行模式，会创建一个命令提示符，处于屏幕底部左侧。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">:q                     # 退出</span><br><span class="line">:q!                    # 强制退出，不保存此前的编辑操作</span><br><span class="line">:wq                    # 保存并退出</span><br><span class="line">:w, :q                 # 保存并退出</span><br><span class="line">:x                     # 保存并退出</span><br><span class="line">:w /PATH/TO/SOMEFILE   # 保存文件至指定的路径</span><br><span class="line">r filename             # 读文件内容到当前文件中</span><br><span class="line">w filename             # 将当前文件内容写入另一个文件</span><br><span class="line">!command               # 执行命令</span><br><span class="line">r!command              # 读入命令的输出</span><br></pre></td></tr></table></figure>

<h4 id="地址定界"><a href="#地址定界" class="headerlink" title="地址定界"></a>地址定界</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">命令格式：</span><br><span class="line">:start_pos[,end_pos]</span><br><span class="line"><span class="meta">	#</span>                           # 特定的第#行，例如5即第5行</span><br><span class="line">	.                           # 当前行</span><br><span class="line"><span class="meta">	$</span>                           # 最后一行</span><br><span class="line"><span class="meta">	#</span>,#                         # 指定行范围，左侧为起始行，右侧为结束行</span><br><span class="line"><span class="meta">	#</span>,+#                        # 指定行范围，左侧为超始行绝对编号，右侧为相对左侧行号的偏移量；例如：3,+7</span><br><span class="line">		.,$-1</span><br><span class="line">		1,$</span><br><span class="line"><span class="meta">	%</span>                           # 全文 </span><br><span class="line">	/pattern/                   # 从光标所在处起始向文件尾部第一次被模式所匹配到的行</span><br><span class="line">		/first/,$</span><br><span class="line">	/pat1/,/pat2/               # 从光标所在处起始，第一次由pat1匹配到的行开始，至第一次由pat2匹配到的行结束之间的所有行</span><br><span class="line">				</span><br><span class="line">可同编辑命令一同使用，实现编辑操作：</span><br><span class="line">	d</span><br><span class="line">	y</span><br><span class="line">	c</span><br><span class="line">				</span><br><span class="line">	w /PATH/TO/SOMEFILE          # 将范围内的文本保存至指定的文件中；</span><br><span class="line">	r  /PATH/FROM/SOMEFILE       # 将指定的文件中的文本读取并插入至指定位置；</span><br></pre></td></tr></table></figure>

<h4 id="查找"><a href="#查找" class="headerlink" title="查找"></a>查找</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">/PATTERN：#从当前光标所在处向文件尾部查找能够被当前模式匹配到的所有字符串；</span><br><span class="line">?PATTERN：#从当前光标所在处向文件首部查找能够被当前模式匹配到的所有字符串；</span><br><span class="line">	n：#下一个，与命令方向相同；</span><br><span class="line">	N：#上一个，与命令方向相反；</span><br><span class="line">	</span><br><span class="line">s：末行模式的命令；使用格式：</span><br><span class="line">	s/要查找的内容/替换为的内容/修饰符</span><br><span class="line">		要查找的内容：可使用正则表达式；</span><br><span class="line">		替换为的内容：不能使用下则表达式，但可以引用；</span><br><span class="line">			如果“要查找的内容”部分在模式中使用分组符号：在“替换为的内容”中使用后向引用；</span><br><span class="line">			直接引用查找模式匹配到的全部文本，要使用&amp;符号；</span><br><span class="line">		修饰符：</span><br><span class="line">			i：忽略大小写；</span><br><span class="line">			g：全局替换，意味着一行中如果匹配到多次，则均替换；</span><br><span class="line">						</span><br><span class="line">	可把分隔符替换为其它非常用字符：</span><br><span class="line">		s@@@</span><br><span class="line"><span class="meta">		s#</span>##</span><br><span class="line"></span><br><span class="line">示例：</span><br><span class="line">1、复制/etc/grub2.cfg文件至/tmp目录中，用查找替换命令删除/tmp/grub2.cfg文件中以空白字符开头的行的行首的空白字符；</span><br><span class="line"><span class="meta">	%</span>s@^[[:space:]]\+@@</span><br><span class="line">2、复制/etc/rc.d/init.d/functions文件至/tmp目录中，用查找替换命令为/tmp/functions文件的每个以空白字符开头的行的行首加上#；</span><br><span class="line"><span class="meta">	%</span>s@^[[:space:]]\+[^[:space:]]@#&amp;@g</span><br><span class="line">3、为/tmp/grub2.cfg文件的前三行的行首加上#号；</span><br><span class="line">	1,3s@^@#@				</span><br><span class="line">4、将/etc/yum.repos.d/CentOS-Base.repo文件中所有的enabled=0替换为enabled=1，所有gpgcheck=0替换为gpgcheck=1；</span><br><span class="line"><span class="meta">	%</span>s@\(enabled\|gpgcheck\)=0@\1=1@g</span><br></pre></td></tr></table></figure>

<h2 id="vim其它功能"><a href="#vim其它功能" class="headerlink" title="vim其它功能"></a>vim其它功能</h2><h3 id="多文件功能"><a href="#多文件功能" class="headerlink" title="多文件功能"></a>多文件功能</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">多文件命令格式：</span><br><span class="line"><span class="meta">#</span> vim FILE1 FILE2 ...</span><br><span class="line">在文件间切换：</span><br><span class="line">	:next  下一个</span><br><span class="line">	:prev  上一个</span><br><span class="line">	:first   第一个 </span><br><span class="line">	:last   最后一个</span><br><span class="line"></span><br><span class="line">退出所有文件：</span><br><span class="line">	:wqall 保存所有文件并退出；</span><br><span class="line">	:wall</span><br><span class="line">	:qall</span><br></pre></td></tr></table></figure>

<h3 id="多窗口功能"><a href="#多窗口功能" class="headerlink" title="多窗口功能"></a>多窗口功能</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">-o：水平分割窗口</span><br><span class="line">-O：垂直分割窗口</span><br><span class="line">			</span><br><span class="line">在窗口间切换：Ctrl+w, ARROW</span><br><span class="line">			</span><br><span class="line">注意：单个文件也可以分割为多个窗口进行查看：</span><br><span class="line">	Ctrl+w, s：水平分割窗口</span><br><span class="line">	Ctrl+w, v：垂直分割窗口</span><br></pre></td></tr></table></figure>

<h3 id="定制vim工作特性"><a href="#定制vim工作特性" class="headerlink" title="定制vim工作特性"></a>定制vim工作特性</h3><p>1、临时有效：在末行模式下的设定，仅对当前vim进程有效</p>
<p>2、永久有效：需要修改相应的配置文件，全局配置文件（/etc/vimrc）；用户个人配置文件（～/.vimrc，需要首先创建此文件）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> 行号</span><br><span class="line">显示：set number, 简写为set nu</span><br><span class="line">取消显示：set nomber, set nonu</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>  括号匹配高亮</span><br><span class="line">匹配：set showmatch, set sm</span><br><span class="line">取消：set nosm</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 自动缩进</span><br><span class="line">启用：set ai</span><br><span class="line">禁用：set noai</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 高亮搜索</span><br><span class="line">启用：set  hlsearch</span><br><span class="line">禁用：set nohlsearch</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 语法高亮</span><br><span class="line">启用：syntax on</span><br><span class="line">禁用：syntax off </span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>忽略字符大小写</span><br><span class="line">启用：set ic</span><br><span class="line">禁用：set noic	</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 获取帮助</span><br><span class="line">:help</span><br><span class="line">:help subject</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span> 按TAB产生4个空格</span><br><span class="line">set ts=4        # 注：ts是tabstop的缩写，设TAB宽4个空格</span><br><span class="line">set expandtab</span><br><span class="line"></span><br><span class="line">对于已保存的文件，可以使用下面的方法进行空格和TAB的替换：</span><br><span class="line">TAB替换为空格：</span><br><span class="line">:set ts=4</span><br><span class="line">:set expandtab</span><br><span class="line">:%retab!</span><br><span class="line"></span><br><span class="line">空格替换为TAB：</span><br><span class="line">:set ts=4</span><br><span class="line">:set noexpandtab</span><br><span class="line">:%retab!</span><br><span class="line"></span><br><span class="line">加!是用于处理非空白字符之后的TAB，即所有的TAB，若不加!，则只处理行首的TAB。</span><br></pre></td></tr></table></figure>

<h2 id="其它"><a href="#其它" class="headerlink" title="其它"></a>其它</h2><p>图片引自网络（侵删）</p>
<p><img src="/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223100320707.png" alt="image-20210223100320707"></p>
<p>来自鸟哥私房菜基础篇：</p>
<p><strong>第一部分</strong>：</p>
<p><img src="/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105458430.png" alt="image-20210223105458430"></p>
<p><img src="/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105516589.png" alt="image-20210223105516589"></p>
<p><img src="/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105529558.png" alt="image-20210223105529558"></p>
<p><strong>第二部分</strong>：</p>
<p><img src="/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105607302.png" alt="image-20210223105607302"></p>
<p><strong>第三部分</strong>：</p>
<p><img src="/2021/02/22/Linux相关/Linux之vim使用详解/image-20210223105625388.png" alt="image-20210223105625388"></p>

      
    </div>

    

    
    
    
    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
      
    </div>

    

    
      
    
    

    

    <footer class="post-footer">
      
        
          
        
        <div class="post-tags">
          
            <a href="/tags/vim使用详解/" rel="tag"># vim使用详解</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2021/02/20/Java数据结构与算法/Java八大排序算法/" rel="next" title="Java八大排序算法">
                <i class="fa fa-chevron-left"></i> Java八大排序算法
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2021/02/23/Linux相关/Linux之find命令/" rel="prev" title="Linux之find命令">
                Linux之find命令 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/geass.jpg" alt="MingRongChen">
            
              <p class="site-author-name" itemprop="name">MingRongChen</p>
              <div class="site-description motion-element" itemprop="description">O Captain! My Captain!</div>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">23</span>
                    <span class="site-state-item-name">posts</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  
                    
                      <a href="/categories/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">9</span>
                    <span class="site-state-item-name">categories</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  
                    
                      <a href="/tags/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">21</span>
                    <span class="site-state-item-name">tags</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://github.com/mingrongchen" title="GitHub &rarr; https://github.com/mingrongchen" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="mailto:825296313@qq.com" title="E-Mail &rarr; mailto:825296313@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
            </div>
          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Linux之vim使用详解"><span class="nav-number">1.</span> <span class="nav-text">Linux之vim使用详解</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#vim简介"><span class="nav-number">1.1.</span> <span class="nav-text">vim简介</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#vim模式"><span class="nav-number">1.1.1.</span> <span class="nav-text">vim模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#vim模式替换"><span class="nav-number">1.1.2.</span> <span class="nav-text">vim模式替换</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#常用vim指令"><span class="nav-number">1.2.</span> <span class="nav-text">常用vim指令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#一般指令模式"><span class="nav-number">1.2.1.</span> <span class="nav-text">一般指令模式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#文件操作"><span class="nav-number">1.2.1.1.</span> <span class="nav-text">文件操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#光标"><span class="nav-number">1.2.1.2.</span> <span class="nav-text">光标</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#翻屏"><span class="nav-number">1.2.1.3.</span> <span class="nav-text">翻屏</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#编辑命令"><span class="nav-number">1.2.1.4.</span> <span class="nav-text">编辑命令</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#命令行命令模式"><span class="nav-number">1.2.2.</span> <span class="nav-text">命令行命令模式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#文件操作-1"><span class="nav-number">1.2.2.1.</span> <span class="nav-text">文件操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#地址定界"><span class="nav-number">1.2.2.2.</span> <span class="nav-text">地址定界</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#查找"><span class="nav-number">1.2.2.3.</span> <span class="nav-text">查找</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#vim其它功能"><span class="nav-number">1.3.</span> <span class="nav-text">vim其它功能</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#多文件功能"><span class="nav-number">1.3.1.</span> <span class="nav-text">多文件功能</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#多窗口功能"><span class="nav-number">1.3.2.</span> <span class="nav-text">多窗口功能</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#定制vim工作特性"><span class="nav-number">1.3.3.</span> <span class="nav-text">定制vim工作特性</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#其它"><span class="nav-number">1.4.</span> <span class="nav-text">其它</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2019 – <span itemprop="copyrightYear">2022</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">MingRong</span>

  

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="post-meta-item-icon">
      <i class="fa fa-user"></i>
    </span>
    <span class="site-uv" title="Total Visitors">
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="post-meta-divider">|</span>
  

  
    <span class="post-meta-item-icon">
      <i class="fa fa-eye"></i>
    </span>
    <span class="site-pv" title="Total Views">
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/utils.js?v=7.2.0"></script>

  <script src="/js/motion.js?v=7.2.0"></script>



  
  


  <script src="/js/affix.js?v=7.2.0"></script>

  <script src="/js/schemes/pisces.js?v=7.2.0"></script>



  
  <script src="/js/scrollspy.js?v=7.2.0"></script>
<script src="/js/post-details.js?v=7.2.0"></script>



  


  <script src="/js/next-boot.js?v=7.2.0"></script>


  

  

  

  


  


  




  

  

  

  

  

  

  

  

  

  

  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"scale":1.5,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/live2dw/assets/z16.model.json"},"display":{"superSample":2,"position":"left","width":150,"height":300,"hOffset":0,"vOffset":-20},"mobile":{"show":false,"scale":0.5,"hOffset":0,"vOffset":-10},"react":{"opacity":0.8,"opacityDefault":0.7,"opacityOnHover":0.2}});</script></body>
</html>
